<?php

/*
 * Copyright 2015 crackerben.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace Com\Log;

use App\wechat\Model;

/**
 * 日志服务
 */
class WriteLog {
    /**
     * 写入数据库日志
     * @param type $content 日志内容
     * @param type $type 日志类型
     * @param type $app 日志app
     * @return boolean 是否成功
     */
    public function WriteLogDB($content, $type,$app) {
        date_default_timezone_set("Asia/Shanghai");
        $time = date("Y-m-d H:G:s", time());
        $log = new \Com\Log\Model\WechatlogModel();
        $res = $log->WriteLog($time, $content, $type,$app);
        return $res;
    }

    /**
     * 写入文件日志
     * @param type $content 日志内容
     * @param type $type 日志类型
     * @param type $app 日志app
     */
    public function WriteLogFile($content,$type,$app) {
        date_default_timezone_set("Asia/Shanghai");
        $time = date("Y-m-d H:G:s", time());
        $fp = fopen(C("LogFile"), 'a');
        fwrite($fp, "Time:  $time |Content: $content |type: $type |app: $app \r\n");
        fclose($fp);
    }

}
